const express=require('express')
const router= express.Router();
const db=require('../../utils/db')

router.get('/getfoodwater', function(req, res, next) {
    let mysql = `SELECT * FROM dish_flowing JOIN menu_file on dish_flowing.dish_name=menu_file.menu_id JOIN 
    pay_method on dish_flowing.dish_payment=pay_method.pay_id join user on dish_flowing.dish_time=user.user_id join order_information 
    on dish_cashier=order_id ORDER BY order_time DESC`
    db(mysql, null, function(err, data) {
        if (err) {
            return res.json({
                code: 500,
                msg: '查询订单信息失败，请稍后重试'
            })
        }
        res.json({
            code: 200,
            msg: '查询订单信息成功',
            data: data
        })
    })
});
// 模糊查询订单
router.get('/getfoodwaterid',function(req,res){
    let mysql=`SELECT * FROM dish_flowing JOIN menu_file on dish_flowing.dish_name=menu_file.menu_id JOIN 
    pay_method on dish_flowing.dish_payment=pay_method.pay_id join user on dish_flowing.dish_time=user.user_id join order_information 
    on dish_cashier=order_id WHERE 1=1 `
    if(req.query.menu_name){
        mysql+=`AND menu_name LIKE '%${req.query.menu_name}%'`
    }
    if(req.query.order_time[0]){
        mysql+=`AND order_time BETWEEN '${req.query.order_time[0]}' AND '${req.query.order_time[1]}'`
    }
    mysql+=` GROUP BY dish_id`
    db(mysql,null,function(err,data){
        if(err){
            return res.json({
                code: 500,
                msg: '模糊查询订单失败，请稍后重试'
            })
        }
        res.json({
            code: 200,
            msg: '模糊查询订单成功',
            data: data
        })
    })
})
module.exports = router